package com.wedata.拼多多;

import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import com.wedata.HttpUtils;

import java.math.BigDecimal;
import java.util.Date;

public class 拼多多 {

    public static void main(String[] args) {
        checkLogin();
        交易数据();
        //推广花费();
    }

    public static void 交易数据() {
        String url = "https://mms.pinduoduo.com/sydney/api/mallTrade/queryMallTradeList";
        JSONObject body =  new JSONObject();
        body.set("queryType", 0);
        body.set("queryDate", "2025-09-07");

        JSONObject result = HttpUtils.sendPost(url, getHeader(), body);
        System.out.println(result);
        JSONArray dayList = result.getJSONObject("result").getJSONArray("dayList");
        for (int i = 0; i < dayList.size(); i++) {
            JSONObject day = dayList.getJSONObject(i);
            System.out.println(day.getDate("stateDate"));
            System.out.println(day.getBigDecimal("payOrdrAmt"));
            System.out.println(day.getBigDecimal("sucRfOrdrAmt1d"));
        }
    }

    //https://mms.pinduoduo.com/home
    public static void 推广花费() {
        String url = "https://mms.pinduoduo.com/sydney/api/mallCoreData/homePagePromotionOverView";
        JSONObject body =  new JSONObject();

        JSONObject result = HttpUtils.sendPost(url, getHeader(), body);
        System.out.println(result);
        JSONArray monthTrend = result.getJSONObject("result").getJSONArray("monthTrend");
        for (int i = 0; i < monthTrend.size(); i++) {
            JSONObject day = monthTrend.getJSONObject(i);
            System.out.println(day.getDate("statDate"));
            BigDecimal promotionSpend = day.getBigDecimal("promotionSpend");
            System.out.println(promotionSpend);
            System.out.println(promotionSpend.divide(new BigDecimal("1000")));
        }
    }

    private static void checkLogin(){
        String url = "https://mms.pinduoduo.com/janus/api/checkLogin";
        JSONObject body =  new JSONObject();
        JSONObject result = HttpUtils.sendPost(url, getHeader(), body);
        System.out.println(result);
    }

    public static JSONObject getHeader() {
        JSONObject header =  new JSONObject();
        header.set("Content-Type", "application/json");
        //header.set("cookie", "api_uid=CioJm2i+RFK8lgBrVSk8Ag==; _nano_fp=XpmynqPblpmbnpXbn9_CbMljWk6NFSmGgXP1UAv7; rckk=goownojZ6AQhkf3xGYc4QFwj55lRv5HN; _bee=goownojZ6AQhkf3xGYc4QFwj55lRv5HN; ru1k=d11964aa-bdb9-4d9e-a5c3-6bbb64214bbf; _f77=d11964aa-bdb9-4d9e-a5c3-6bbb64214bbf; ru2k=fbf105c5-e561-4408-9733-f635bc567364; _a42=fbf105c5-e561-4408-9733-f635bc567364; PASS_ID=1-Nua+xymhvOL250YAgkcvrU+PYyeTbDgmau3qM3t/8wSjY6tIFFN3EYWKupxQQxdjviVpaw2xYhyhyx6eDpsg/g_966873828_170552813; windows_app_shop_token_23=eyJ0IjoiNnljWVhVOS9jWUlUaUh5ZHVHSk1sZWllSzdpdUcyTjU4eXYyZWp1K3R1WkZUUXNaYWdpa2F4OVdLa25MMFBhSSIsInYiOjEsInMiOjIzLCJtIjo5NjY4NzM4MjgsInUiOjE3MDU1MjgxM30; x-visit-time=1757299951817; JSESSIONID=D6EE5DDDF2EA44775C42212E2549CEA2; mms_b84d1838=3616,3523,3660,3614,3586,3599,3601,3603,3605,3621,3622,3669,3588,3254,3531,3559,3482,1202,1203,1204,1205,3417");
        header.set("cookie", "PASS_ID=1-ODXlPnghJCuam+6CQ30D+cSy7iMnZKj921NVj0SnICIYkR3yUb2UtKLZACIi+qi0UidrwlJqwa5JANCGBPWfNg_966873828_170552813;");
        return header;
    }
}
